-
Notifications
You must be signed in to change notification settings - Fork 75
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
multipart/form-data support for typespec-todo #2984
Conversation
c2e63bd
to
8c0bd25
Compare
@@ -646,6 +646,9 @@ export interface FileContentResponse { | |||
content: Uint8Array; | |||
} | |||
|
|||
// @public | |||
export type FileContents = string | NodeJS.ReadableStream | ReadableStream<Uint8Array> | Uint8Array | Blob; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just curious why this is added? is this expected?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like this spec has an anonymous model for MFD which isn't properly supported yet. FileContents
should be used in uploadFile
but is currently Uint8Array
. Will fix.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will address anonymous models including this case in a follow up issue
packages/typespec-ts/test/modularUnit/scenarios/multipart/file.md
Outdated
Show resolved
Hide resolved
packages/typespec-ts/test/modularUnit/scenarios/multipart/file.md
Outdated
Show resolved
Hide resolved
packages/typespec-ts/test/modularUnit/scenarios/multipart/file.md
Outdated
Show resolved
Hide resolved
|
||
```tsp | ||
model RequestBody { | ||
files: HttpPart<File>[]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we add a case for
model RequestBody {
files: HttpPart<File[]>;
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think that case really makes sense. That body model would represent a single part consisting of a JSON array of File
objects.
We do already have a case for a JSON array here.
@@ -128,6 +130,9 @@ function emitType(context: SdkContext, type: SdkType, sourceFile: SourceFile) { | |||
if (isAzureCoreErrorType(context.program, type.__raw)) { | |||
return; | |||
} | |||
if (isOrExtendsHttpFile(context.program, type.__raw!)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if we could use usage to filter the HttpPart models out?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can't because tcgc doesn't set UsageFlags.MultipartFormData for Http.File
. It only does that for the actual multipart body model.
); | ||
if ( | ||
!properties.some((x) => x.name === name) && | ||
!(existInterface && existInterface.getProperty(name)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder why we need this filter? do you see any cases where there's duplication?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, the multipart payload cadl ranch spec causes this duplication for some reason. If you revert this change and regenerate you should see the issue.
NameType.Property | ||
); | ||
|
||
// HACK: check if the statement includes a group of this name already to prevent an operation group appearing multiple times |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel like it's strange if an operation group would appear multiple times. how could I repro?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same issue as above -- without this the multipart spec generates the group 3 times. I think it might have to do with the way that the operations are nested?
packages/typespec-test/test/todo_non_branded/generated/openapi/openapi.json
Show resolved
Hide resolved
packages/typespec-ts/test/modularUnit/scenarios/example/example.md
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
parts.push(partDefinition); | ||
} | ||
|
||
// TODO: How to handle additionalProperties for MFD? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is there an issue to track this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added it to the follow up issue #3001
multipart/form-data
support for the cases covered by the todo spec for the e2e demo.Includes basic support for file uploads, JSON, and text parts. There are some items to follow up on after this PR:
@multipartBody
are not currently supportedFixes #2422